﻿using System.Collections.Generic;
using SFML.Graphics;

namespace Transformable_Engine_v2.Engine.Global
{
    public static class RenderTargetHandler
    {
        const string DefaultRender = "DEFAULT_RENDER";
        private static Dictionary<string, RenderTarget> _renderTargets;
        private static string _currentRender;

        /// <summary>
        /// Initializes the RenderTargetHandler
        /// </summary>
        /// <param name="window">Default window</param>
        public static void Initialize(RenderTarget window)
        {
            _renderTargets = new Dictionary<string, RenderTarget>();

            Add(DefaultRender, window);
            _currentRender = DefaultRender;
        }

        public static void Add(string targetName, float renderTargetWidth, float renderTargetHeight)
        {
            _renderTargets.Add(targetName, new RenderTexture((uint) (renderTargetWidth * Game.Options.GridSize), (uint) (renderTargetHeight * Game.Options.GridSize)));
        }
        public static void Add(string targetName, RenderTarget renderTarget)
        {
            _renderTargets.Add(targetName, renderTarget);
        }

        public static RenderTarget GetCurrentRenderTarget()
        {
            return _renderTargets[_currentRender];
        }
        public static void ClearCurrentTarget(Color color)
        {
            _renderTargets[_currentRender].Clear(color);
        }

        public static void ChangeCurrentRenderTarget(string key)
        {
            _currentRender = key;
        }
        public static void RevertToDefaultRenderTarget()
        {
            _currentRender = DefaultRender;
        }
    }
}